<?php
/**
 * Created by PhpStorm
 * User: 龍zero
 * Date: 2022-04-10
 * Time: 16:28
 */
declare(strict_types=1);

namespace App\Request\Admin;

use Hyperf\Validation\Request\FormRequest;

class GroupRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     */
    public function authorize(): bool
    {
        return true;
    }

    protected array $scenes = [
        'create' => ['name','info','permission_ids','permission_ids.*'],
        'update' => ['name', 'info'],
    ];

    /**
     * Get the validation rules that apply to the request.
     */
    public function rules(): array
    {
        return [
            'name' => 'required|between:2,20',
            'info' => 'required|between:2,20',
            'permission_ids' => 'array',
            'permission_ids.*' => 'positive'
        ];
    }
    /**
     * 获取已定义验证规则的错误消息
     */
    public function messages(): array
    {
        return [
            'name.required' => '权限分组名称必填',
            'name.between' => '权限分组名称必须在2-20个字符之间',
            'info.required'  => '权限分组描述必填',
            'info.between'  => '分组描述必须在2-20个字符之间',
            'permission_ids.array' => '权限id必须为数组格式'
        ];
    }
}
